package com.smart.parking.service.impl;


import com.smart.parking.entity.SpaceEntity;
import com.smart.parking.service.RepairService;
import com.smart.parking.service.SpaceService;
import com.smart.parking.utils.PageUtils;
import com.smart.parking.utils.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


import com.smart.parking.mapper.RepairMapper;
import com.smart.parking.entity.RepairEntity;



@Service("repairService")
public class RepairServiceImpl extends ServiceImpl<RepairMapper, RepairEntity> implements RepairService {


    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<RepairEntity> page = this.page(
                new Query<RepairEntity>().getPage(params),
                new QueryWrapper<RepairEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * 添加维修记录
     *
     * @param repairEntity 修复实体
     */
    @Override
    public void addRepair(RepairEntity repairEntity) {
        baseMapper.insert(repairEntity);
    }

//    /**
//     * 更新维修状态
//     *
//     * @param repairID 修复id
//     * @param state    状态
//     */
//    @Override
//    public void updateRepair(Long repairID, Integer state) {
//        if (state == 3){
//            //维修完成
//            RepairEntity repairEntity = baseMapper.selectById(repairID);
//            repairEntity.setRepairState(state);
//            baseMapper.updateById(repairEntity);
//            this.completeParking(repairEntity.getSpaceId());
//        }else {
//            RepairEntity repairEntity = baseMapper.selectById(repairID);
//            repairEntity.setRepairState(state);
//            baseMapper.updateById(repairEntity);
//        }
//    }
//
//    /**
//     * 完成车位恢复
//     *
//     * @param spaceId 车位id
//     */
//    @Override
//    public void completeParking(Long spaceId) {
//        //修复成功
//        SpaceEntity spaceEntity = spaceService.getById(spaceId);
//        //更改为可用
//        spaceEntity.setSpaceDamage(0);
//        spaceService.updateById(spaceEntity);
//    }

}
